<?php
namespace app\api\controller\wanlshop;

use addons\epay\library\Service;
use app\common\controller\Api;

class Fenzhang extends Api
{
    protected $noNeedLogin = [];
    protected $noNeedRight = ['*'];

    public function _initialize()
    {
        parent::_initialize();
        // 切换v3支付
        set_addon_config('epay', ['version'=>'v3'], false);
    }

    //分账
    public function subAccount()
    {
        $config = Service::getConfig('wechat');
        $receivers = [
            [
                'type'=>'MERCHANT_ID',
                'account'=>'1624428553',
                'amount'=>1,
                'description'=>'分账'
            ]
        ];
        $response = \Yansongda\Pay\Pay::wechat($config)->profitsharing([
            //'type'          => 'miniapp',
            'out_order_no'  => '202506181451177749220553545310',
            'transaction_id'=> '4200002646202506182750864586',
            'receivers'     => $receivers,
            'unfreeze_unsplit'=>false
        ]);
        //dump($response);die;
        //dump($response->state);die;
        $this->success('',$response);
    }

    //查询分账结果
    public function searchOrdersResult()
    {
        $config = Service::getConfig('wechat');

        $response = \Yansongda\Pay\Pay::wechat($config)->queryProfitsharing([
            //'type'          => 'miniapp',
            'out_order_no'  => '20250613153449445189985799545500',
            'transaction_id'=> '4200002637202506138414321851',
        ]);
        $this->success('',$response);
    }
}